<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@ include file="/taglibs.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<%@ include file="/uilibs.jsp"%>
<style type="text/css">

</style>
</head>
<body>
<div class="mini-fit">
    <div class="mini-toolbar" style="border-bottom: 0; padding: 0px;">
        <table style="width: 100%;" border="0">
            <tr>
                <td>
                    <a class="mini-button" iconCls="icon-save" onclick="save">保存</a> 
                    <a class="mini-button" iconCls="icon-reload" onclick="refresh">刷新</a> 
                    <span class="separator"></span>
                    <a class="mini-button" iconCls="icon-add" onclick="add">添加</a> 
                    <a class="mini-button" iconCls="icon-remove" onclick="del">删除</a> 
                    <span class="separator"></span>
                </td>
                <td style="width:60px;">字典名称:</td>
                <td>
                <input name="name" id="name" style="width:150px;" required="true" class="mini-textbox" value="${name}"/>
                </td>
            </tr>
        </table>
    </div>
    <div class="mini-fit">
    <div id="grid" class="mini-datagrid" style="width:100%;height:100%;" showPager="false"
        url="${ctx}/system/common/grid" idField="id" multiSelect="true" allowCellEdit="true" allowCellSelect="true" editNextOnEnterKey="true"  editNextRowCell="true">
        <div property="columns">
            <div type="checkcolumn"></div>
            <div field="key" width="60" headerAlign="center" allowSort="true">键
            <input property="editor" class="mini-textbox" style="width:120;" minWidth="200" />
            </div>
            <div field="value" width="60" headerAlign="center" allowSort="true">值
            <input property="editor" class="mini-textbox" style="width:120;" minWidth="200" />
            </div>
        </div>
    </div>
    </div>
</div>
<script type="text/javascript">
var grid;

$(function(){
    mini.parse();
    grid = mini.get("grid");
    var params={};
    params.sql="select * from system_dict where name='${name}'";
    grid.load(params);
});

function add(){
    var newRow = { name: "New Row" };
    grid.addRow(newRow, 0);
    grid.beginEditCell(newRow);
}

function del(){
    var rows = grid.getSelecteds();
    if (rows.length > 0) {
        grid.removeRows(rows, true);
    }
}

function refresh(){
    grid.reload();
}

function save() {
    var array = grid.getChanges();
    var name = mini.get("name").getValue();
    if(!name||name==''){
        mini.alert("字典名称不能为空！");
        return;
    }
    $.post("${ctx}/system/dict/save",{name:name,array:JSON.stringify(array)},function(data){
          if(data){
            mini.alert("保存成功！","系统提示",function(){
                CloseWindow("ok");
            });
          } else {
            mini.alert("服务器繁忙，请稍后重试");
          }
    });
}

function CloseWindow(action) {
    if (action == "close" && form.isChanged()) {
        if (confirm("数据被修改了，是否保存先？")) {
            return false;
        }
    }
    if (window.CloseOwnerWindow) return window.CloseOwnerWindow(action);
    else window.close();
}

</script>
</body>
</html>